//
//  SelectVC.m
//  SelfDrivingTravelling-IOS
//
//  Created by Teplot_01 on 16/8/11.
//  Copyright © 2016年 Teplot_01. All rights reserved.
//

#import "SelectVC.h"
#import "selectCell.h"
@interface SelectVC ()<UITableViewDelegate,UITableViewDataSource>

@end

@implementation SelectVC
{
    selectCell *cell;
    NSIndexPath *_selIndex;//单选，当前选中的行
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];
    [self initTableView];
}
- (void)initTableView{
    UITableView *_tableView = [[UITableView alloc]initWithFrame:self.view.frame];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    [self.view addSubview:_tableView];
}
#pragma -mark UITabelViewDelegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 10;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    cell = [[NSBundle mainBundle]loadNibNamed:@"selectCell" owner:nil options:nil][0];
    cell.tintColor = Theme_Color;
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    //当上下拉动的时候，因为cell的复用性，我们需要重新判断一下哪一行是打勾的
    if (_selIndex == indexPath) {
        cell.accessoryType = UITableViewCellAccessoryCheckmark;
    }else {
        cell.accessoryType = UITableViewCellAccessoryNone;
    }

    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    //之前选中的，取消选择
    UITableViewCell *celled = [tableView cellForRowAtIndexPath:_selIndex];
    celled.accessoryType = UITableViewCellAccessoryNone;
    //记录当前选中的位置索引
    _selIndex = indexPath;
    //当前选择的打勾
    UITableViewCell *celll = [tableView cellForRowAtIndexPath:indexPath];
    celll.accessoryType = UITableViewCellAccessoryCheckmark;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 90;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
